<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>test-1</title>
        <script type="text/javascript" src="../dist/need.js" ></script>
        <style>
        	#output{
				margin:10px;
			}
			#output p{
				box-shadow:0 0 5px rgba(0,0,0,.5);
				border:1px solid rgb(200,200,200);
				border-radius:5px;
				line-height:2em;
				text-align:2em;
			}
			#output p span{
				margin:0 5px;
				padding:0.5em 5px 0.5em 0;
				border-right:1px solid rgb(200,200,200);
			}
			#output p span.title{
				background-color:#000;
				color:#fff;
				padding:0.5em;
				margin:0px;
				border-radius:5px 0 0 5px;
			}
        </style>
	</head>
	<body>
        <div id='output'></div>
        <script type="text/javascript" >
        function output(str,title){
			var p = document.createElement('p') , span = null ;
			p.innerHTML = '<span class="title">'+title+'</span>' ;
			if(typeof(str)==='object'){
				for(var i in str){
					span = document.createElement('span') ;
					span.innerHTML = i+':'+str[i] ;
					p.appendChild(span);
				}
			}else{
				span = document.createElement('span');
				span.innerHTML = str+''
				p.appendChild(span) ;
			}
			document.getElementById('output').appendChild(p) ;
		} ;
		(function(w){		
			
			need.on('runFail',function(mode){
				output(mode,'runFail');
			})
			
			need.on('undefine',function(id){
				output(id,'undefine');
			});
			
			need.on('same',function(mode){
				output(mode,'same') ;
			}) ;
			
        }(window)) ;
		
		//若一个模块报错 , 会触发runFail事件
		put('throwError',function(){
			var i = 0 ;
			for( i = 0 ; i < 10000 ; i++  ){}
			throw new Error(' There is an Error ') ;
			return i ;
		}) ;
		
		//一个模块的依赖模块发生错误,依赖模块会返回undefined,该模块依旧执行
		put('runOnError',['throwError'],function(e){
			var i ;
			for( i = 0 ; i < 10000 ; i++ ){}
			output(e,'runOnError');
			return i;
		}) ;
		
		put('runOnUndefine',['some'],function(the){
			output(the,'runOnUndefine');
			return 0 ;
		}) ;
		
		//无法捕获异步代码的报错 同时异步代码的错误也不会影响其他代码的执行
 		put('aysncError',function(){
			window.setTimeout(function(){
				throw new Error('There is an Error') ;
			},3) ;
		}) ;
		
		(function(w){
			
			var aysncError = need('aysncError') ;
			var throwError = need('throwError') ;
			var runOnError = need('runOnError') ;
			//var undefineMode = need('some') ;
			var runOnUndefine = need('runOnUndefine') ;
			
		}(window)) ;
		
        </script>
   	</body>
</html>